package br.diego.tb.elementaryData;

public class PairProduct 
{

    public static int max_prod(Integer[] v) {
    	
    	int biggestDivisibleBy3 = 0;
    	int biggestOther = 0;
    	
    	int previousBiggestDivisibleBy3 = 0;
    	
    	for(int i = 0; i < v.length; i ++)
    	{
    		if(v[i] % 3 == 0)
    		{
    			if(v[i] > biggestDivisibleBy3)
    			{
    				previousBiggestDivisibleBy3 = biggestDivisibleBy3; 
    				biggestDivisibleBy3 = v[i];
    				
    				biggestOther = previousBiggestDivisibleBy3 > biggestOther ? previousBiggestDivisibleBy3 : biggestOther;
    				continue;
    			}
    		}

    		biggestOther = v[i] > biggestOther ? v[i] : biggestOther;
    	}
    	
    	int product = biggestDivisibleBy3 * biggestOther;
    	
    	System.out.println(product);
    	
    	return product;
    }
}
